package com.pearadmin.pro.modules.paper.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pearadmin.pro.common.aop.annotation.Log;
import com.pearadmin.pro.common.constant.ControllerConstant;
import com.pearadmin.pro.common.web.base.BaseController;
import com.pearadmin.pro.common.web.domain.Result;
import com.pearadmin.pro.modules.examUtils.PagingReqDTO;
import com.pearadmin.pro.modules.paper.dto.UserBookDTO;
import com.pearadmin.pro.modules.paper.entity.UserBook;
import com.pearadmin.pro.modules.paper.service.UserBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Map;

/**
 * 错题本控制器
 *
 * @author ZhouXingYun
 * @date 2022/5/25 14:06
 */
@Api(tags = {"错题本"})
@RestController
@RequestMapping(ControllerConstant.PREFIX_SYS + "wrong-book")
public class UserBookController extends BaseController {

    @Autowired
    private UserBookService baseService;
    public DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * 错题本分页
     *
     * @return ApiRest<IPage < UserBookDTO>>
     * @author ZhouXingYun
     * @date 2022/5/25 14:07
     */
    @ApiOperation(value = "错题本分页")
    @Log(title = "错题本分页")
    @RequestMapping(value = "/paging", method = {RequestMethod.POST})
    public Result<IPage<UserBookDTO>> paging(@RequestBody Map<String, String> param) {
        PagingReqDTO<UserBookDTO> reqDTO = new PagingReqDTO<>();
        reqDTO.setCurrent(Integer.valueOf(param.get("pageNum")));
        reqDTO.setSize(Integer.valueOf(param.get("pageSize")));
        UserBookDTO userBookDTO = new UserBookDTO();
        userBookDTO.setExamId(param.get("examId"));
        reqDTO.setParams(userBookDTO);
        //分页查询并转换
        IPage<UserBookDTO> page = baseService.paging(reqDTO);
        page.getRecords().forEach(userBookDTO1 -> {
//            userBookDTO1.setUpdateTime(userBookDTO1.getUpdateTime());
        });
        return success(page);
    }

}
